package com.service.generic_service;

import com.mapper.MenuMapper;
import com.pojo.Menu;
import com.service.iter.generic_service.IMenuService;
import com.util.Res;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;

/**
 * 菜单服务impl
 *
 * @author admin
 * @date 2023/06/19
 */
@Service
@Transactional
public class MenuServiceImpl implements IMenuService {
    /**
     * 菜单映射器
     */
    @Autowired
    private MenuMapper menuMapper;

    /**
     * 得到菜单
     *
     * @param role 角色
     * @return {@link Res}
     */
    @Override
    public Res getMenus(Long role) {
        System.out.println(menuMapper);
        Res res = new Res();
        System.out.println(role);
        List<Menu> menus = menuMapper.getMenus(role);
        System.out.println(menus);
        if (Objects.isNull(menus)) {
            res.setMsg("未知角色");
            res.setCode(400);
        } else {
            res.setData(menus);
            res.setCode(200);
        }
        return res;
    }
}
